using System;
using System.Collections;
using System.Collections.Generic;
using TowerDefence_Study;
using UnityEngine;
using UnityEngine.UI;

namespace TowerDefence
{
    public class UILayer : MonoBehaviour
    {
        private void Start()
        {
            OnEnter();
        }

        private void OnDestroy()
        {
            OnExit();
        }

        public void InitNode(Transform tf)
        {
            OnNodeAsset(tf.name, tf.gameObject);
            var btn = tf.GetComponent<Button>();
            if (btn != null)
            {
                btn.onClick.AddListener(()=>
                {
                    OnButtonClick(btn.name,btn.gameObject);
                });
            }
            for (int i = 0; i < tf.childCount; i++)
            {
                InitNode(tf.GetChild(i));
            }
        }

        public virtual void OnNodeLoad()
        {
            
        }

        public virtual void OnEnter()
        {
            
        }

        public virtual void OnExit()
        {
            
        }


        public void Close()
        {
            UIManager.ExitUI(this);
        }
        
        protected virtual void OnNodeAsset(string name, GameObject obj)
        {
           
        }
        

        protected virtual void OnButtonClick(string name, GameObject obj)
        {
           
        }
    }
}

